<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>set</title>
</head>
<body>

<script>
    const set = new Set();
    [2,3,1,5,4,2,6,7,9,2,3,6].forEach(x=>set.add(x));

    for(let i of set){
        console.log(i);
    }

    console.log("set size : ", set.size)

    const set1 = new Set([1, 2, 3, 4, 4]);
    set1.forEach(key => console.log(key))
    set1.forEach((key,value)=>console.log(key +' : '+ value))

    //set 遍历 key和value是一致的 keys values entries(返回数组)
    let set2 = new Set(['red', 'green', 'blue']);
    for(let item of set2.entries()){
        console.log(item)
    }

    let set3 = new Set([1, 2, 3]);

    console.log(new Set([... set3].map(x => x * 2)))

    const a = [[1, 2], [3, 4]];
    const ws = new WeakSet(a);
    console.log("begin:" , ws);
    const b = [5,6];

    ws.add(b);
    const c = [7,8];
    ws.add(c)
    console.log("end :", ws);

    const ws2 = new WeakSet();
    const obj = {};
    const foo = {};

    ws2.add(window);
    ws2.add(obj);

    console.log(ws2.has(window)); // true
    console.log(ws2.has(foo)); // false

    ws2.delete(window);
    ws2.has(window);

</script>
</body>
</html>